<template>
  <div>
    <page-list :x-uri="uri" :x-tabs="tabs" :doactions="doactions" :checkbox-item="false" :custom-components="custom" :draggable="false" :pagination="false">
      <!-- 页面操作按钮 -->
      <template v-slot:page-button>
        <el-button v-auth="'market.advert'" size="mini" type="primary" @click="create">新建</el-button>
      </template>
    </page-list>
  </div>
</template>

<script>
import PageList from '@public/template/page_list.vue';
import Image from './components/image.vue';
import LinkInfo from './components/link_info.vue';
import LinkTypeText from './components/link_type_text.vue';
export default {
  components: {
    PageList
  },
  inject: ['reload'],
  data() {
    return {
      uri: '/admin/market/advert/' + this.$route.params.id + '/manage/list',
      tabs: [
        {
          title: '广告图管理',
          uri: '/market/advert/list',
          meta: {
            permission: 'market.advert'
          }
        },
        {
          title: '广告内容管理',
          uri: '/market/advert/' + this.$route.params.id + '/manage',
          meta: {
            permission: 'market.advert'
          }
        }
      ],
      doactions: [{ title: '编辑', meta: { permission: 'market.advert' }, callback: this.edit }, { title: '删除', meta: { permission: 'market.advert' }, callback: this.delete }],
      custom: {
        image: Image,
        link_to: LinkInfo,
        link_type_text: LinkTypeText
      }
    };
  },
  methods: {
    create: function() {
      this.$router.push({ path: '/market/advert/' + this.$route.params.id + '/manage/create' });
    },
    edit: function({ row }) {
      this.$router.push({ path: '/market/advert/' + this.$route.params.id + '/manage/' + row.id + '/edit' });
    },
    delete: function({ row }) {
      this.$box
        .confirm('确认删除吗')
        .then(() => {
          this.$http.delete(
            '/admin/market/advert/' + this.$route.params.id + '/manage/' + row.id,
            {},
            response => {
              this.$message.success(response.msg, _ => {
                this.reload();
              });
            },
            error => {
              this.$message.error(error.msg);
            }
          );
        })
        .catch(() => {});
    }
  }
};
</script>
